package com.lyshop.jinxiang.adapters;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lyshop.jinxiang.R;
import com.lyshop.jinxiang.base.BaseRVAdapter;
import com.lyshop.jinxiang.base.BaseRVHolder;
import com.lyshop.jinxiang.base.BaseViewHolder;
import com.lyshop.jinxiang.bean.RetailOrderBean;
import com.lyshop.jinxiang.utils.ToastUtil;
import com.lyshop.jinxiang.view.MoneyTextView;

import java.util.List;

public class RetailOrderAdapter extends BaseRVAdapter {
    public RetailOrderAdapter(Context context, List list) {
        super(context, list);
    }

    @Override
    public int onCreateViewLayoutID(int viewType) {
        return R.layout.item_retail_order;
    }

    @Override
    public void onBindView(BaseRVHolder holder, int position) {
        BaseViewHolder mHolder = holder.getViewHolder();
        TextView tv_order_no = mHolder.get(R.id.tv_order_no);
        TextView tv_goods_name = mHolder.get(R.id.tv_goods_name);
        TextView tv_order_status = mHolder.get(R.id.tv_order_status);
        ImageView iv_goods = mHolder.get(R.id.iv_goods);
        MoneyTextView mtv_goods_money = mHolder.get(R.id.mtv_goods_money);
        TextView tv_goods_number = mHolder.get(R.id.tv_goods_number);
        TextView tv_describe = mHolder.get(R.id.tv_describe);
        Button bt_submit = mHolder.get(R.id.bt_submit);
        RetailOrderBean bean =(RetailOrderBean)mList.get(position);
        String orderNo = "订单编号：" + bean.getOrder_id();
        String number = "x" + bean.getAmount();
        String proName = bean.getName();
        String money = String.valueOf(bean.getPrice());
        String describe = "共" + bean.getAmount() + "件 实付￥" + bean.getMoney_sum();

        Glide.with(mContext).load(bean.getGoods_img()).into(iv_goods);

        tv_order_no.setText(orderNo);
        tv_goods_name.setText(proName);
        tv_goods_number.setText(number);
        mtv_goods_money.setText(money);
        tv_describe.setText(describe);

        bt_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(bean.getStatus() ==1){
                    ToastUtil.showToast(mContext,"请联系客服");
                    return;
                } else if (bean.getStatus() ==2) {
                    mListener.onConfirm(bean.getOrder_id());
                }
            }
        });

        bt_submit.setVisibility(View.GONE);
        switch (bean.getStatus()) {
            case 1:
                //待发货
                tv_order_status.setText("待发货");
                tv_order_status.setTextColor(mContext.getResources().getColor(R.color.color_477ae5));
                bt_submit.setVisibility(View.VISIBLE);
                bt_submit.setText("取消订单");
                break;
            case 2:
                //提货中
                tv_order_status.setText("待收货");
                tv_order_status.setTextColor(mContext.getResources().getColor(R.color.color_477ae5));
                bt_submit.setVisibility(View.VISIBLE);
                bt_submit.setText("确认收货");
                break;
            case 3:
                //成功
                tv_order_status.setTextColor(mContext.getResources().getColor(R.color.color_gray_02));
                tv_order_status.setText("已完成");
                bt_submit.setVisibility(View.GONE);
                break;
            case 9:
                //失败
                tv_order_status.setTextColor(mContext.getResources().getColor(R.color.color_gray_02));
                tv_order_status.setText("已失败");
                bt_submit.setVisibility(View.GONE);
                break;
        }
    }

    public interface OrderConfirmListener{
        void onConfirm(String order_id);
    }

    private OrderConfirmListener mListener;

    public void setListener(OrderConfirmListener listener){
        this.mListener = listener;
    }
}
